package net.xo68.destiny.manager.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.xo68.destiny.contract.domain.StringRespondResult;
import net.xo68.destiny.manager.entity.JobInstance;
import net.xo68.destiny.manager.service.JobInstanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/** 
 * JobInstance controller
 * @author wuxie(16349023@qq.com)
 * @date 2020年12月21日 21:43:52
 *
 */
 @Api(value = "任务实例",tags = {"任务实例"})
@RequestMapping("/JobInstance")
@Slf4j
@RestController
public class JobInstanceController{

    @Autowired
    private JobInstanceService jobInstanceService;

    @ApiOperation(value="详情")
	@GetMapping("/detail/{instanceId}")
    public JobInstance detail(@PathVariable(name="instanceId") Long instanceId) {
        return jobInstanceService.find(instanceId);
    }
    
    @ApiOperation(value="翻页列表")
    @GetMapping("/list")
    public PageInfo<JobInstance> list(@RequestParam(name="pageIndex",defaultValue="1") int pageIndex,@RequestParam(name="pageSize",defaultValue="10") int pageSize){
        return jobInstanceService.list(pageIndex, pageSize);
    }
	
    @ApiOperation(value="创建")
	@PostMapping
    public JobInstance add(@RequestBody JobInstance entity ) {
        return jobInstanceService.insert(entity);
    }
	
    @ApiOperation(value="删除")
	@DeleteMapping
	public StringRespondResult delete(@RequestParam(name="id") Long id) {
        int effect=jobInstanceService.delete(id);
        if(effect< 1){
            return StringRespondResult.fail();
        }
        return StringRespondResult.ok();
	}
	
    @ApiOperation(value="更新")
	@PutMapping
	public JobInstance update(@RequestBody JobInstance entity) {
	    return jobInstanceService.update(entity);
	}
}